import os.path
import wx.stc as stc

from utils.iniParser import IniParser

class Language(object):
  def __init__(self):
    pass

  def getDefaultIndentStyles(self):
    return {'Size':'4',
           'ShowIndentGuide':'true',
           'BackspaceUnindents':'true',
           'TabIndents':'true',
           'TabWidth':'4',
           'UseTabs':'true',
           'ViewWhitespace':'true'}

  def getDefaultStyles(self):
    return None

  def getGlobalStyles(self):
    configFilePath = os.path.dirname(__file__)
    configFile = os.path.normpath(configFilePath) + os.path.sep + 'hstyles' + os.path.sep + 'global.ini'

    if not os.path.exists(configFile):
      return None

    parser = IniParser()
    return parser.parse(configFile)

  def getStyles(self):
    configFilePath = os.path.dirname(__file__)
    configFile = os.path.normpath(configFilePath) + os.path.sep + 'hstyles' + os.path.sep + self.getConfigFileName()

    if not os.path.exists(configFile):
      defaultStyles = self.getDefaultStyles()
      if defaultStyles is None:
        return self.getGlobalStyles()
      else:
        return defaultStyles

    parser = IniParser()
    return parser.parse(configFile)

  def getHighlightSymbols(self):
    return None

  def getCommentSymbols(self):
    return ('', '')

  def getConfigFileName(self):
    return 'global.ini'

class Python(Language):
  def __init__(self):
    Language.__init__(self)

  def getDefaultStyles(self):
    return {'Default':('Courier','10','black','white','false', 'false'),
           'CommentLine':('Courier','10','black','white','false', 'false'),
           'Number':('Courier','10','black','white','false', 'false'),
           'String':('Courier','10','black','white','false', 'false'),
           'Character':('Courier','10','black','white','false', 'false'),
           'Word':('Courier','10','black','white','false', 'false'),
           'Triple':('Courier','10','black','white','false', 'false'),
           'TripleDouble':('Courier','10','black','white','false', 'false'),
           'ClassName':('Courier','10','black','white','false', 'false'),
           'DefName':('Courier','10','black','white','false', 'false'),
           'Operator':('Courier','10','black','white','false', 'false'),
           'Identifier':('Courier','10','black','white','false', 'false'),
           'CommentBlock':('Courier','10','black','white','false', 'false'),
           'StringEOL':('Courier','10','black','white','false', 'false')}

  def getHighlightSymbols(self):
    return {'Default':stc.STC_P_DEFAULT, 
            'CommentLine':stc.STC_P_COMMENTLINE,  
            'Number':stc.STC_P_NUMBER,  
            'String':stc.STC_P_STRING,  
            'Character':stc.STC_P_CHARACTER, 
            'Word':stc.STC_P_WORD,  
            'Triple':stc.STC_P_TRIPLE,  
            'TripleDouble':stc.STC_P_TRIPLEDOUBLE,  
            'ClassName':stc.STC_P_CLASSNAME,  
            'DefName':stc.STC_P_DEFNAME, 
            'Operator':stc.STC_P_OPERATOR,  
            'Identifier':stc.STC_P_IDENTIFIER,  
            'CommentBlock':stc.STC_P_COMMENTBLOCK,  
            'StringEOL':stc.STC_P_STRINGEOL}

  def getCommentSymbols(self):
    return ('##', '')

  def getConfigFileName(self):    
    return 'python.ini'

class Xml(Language):
  def __init__(self):
    Language.__init__(self)

  def getConfigFileName(self):    
    return 'xml.ini'

  def getCommentSymbols(self):
    return ('<!--', '-->')


###################################################################################
## Gloabl Defination

LANGUAGE_PYTHON = 'python'
LANGUAGE_XML = 'xml'

Languages = {LANGUAGE_PYTHON:Python(), 
            LANGUAGE_XML:Xml()}

def getDefination(language):
  if Languages.has_key(language.lower()):
    return Languages[language.lower()]
  return Language()

def getMarkerStyles():
  return {'ArrowPoint':{stc.STC_MARKNUM_FOLDEROPEN:stc.STC_MARK_ARROWDOWN,
                       stc.STC_MARKNUM_FOLDER:stc.STC_MARK_ARROW,
                       stc.STC_MARKNUM_FOLDERSUB:stc.STC_MARK_EMPTY,
                       stc.STC_MARKNUM_FOLDERTAIL:stc.STC_MARK_EMPTY,
                       stc.STC_MARKNUM_FOLDEREND:stc.STC_MARK_EMPTY,
                       stc.STC_MARKNUM_FOLDEROPENMID:stc.STC_MARK_EMPTY,
                       stc.STC_MARKNUM_FOLDERMIDTAIL:stc.STC_MARK_EMPTY},
         'Plus':{stc.STC_MARKNUM_FOLDEROPEN:stc.STC_MARK_MINUS,
                 stc.STC_MARKNUM_FOLDER:stc.STC_MARK_PLUS,
                 stc.STC_MARKNUM_FOLDERSUB:stc.STC_MARK_EMPTY,
                 stc.STC_MARKNUM_FOLDERTAIL:stc.STC_MARK_EMPTY,
                 stc.STC_MARKNUM_FOLDEREND:stc.STC_MARK_EMPTY,
                 stc.STC_MARKNUM_FOLDEROPENMID:stc.STC_MARK_EMPTY,
                 stc.STC_MARKNUM_FOLDERMIDTAIL:stc.STC_MARK_EMPTY},
         'Circular':{stc.STC_MARKNUM_FOLDEROPEN:stc.STC_MARK_CIRCLEMINUS,
                     stc.STC_MARKNUM_FOLDER:stc.STC_MARK_CIRCLEMINUS,
                     stc.STC_MARKNUM_FOLDERSUB:stc.STC_MARK_VLINE,
                     stc.STC_MARKNUM_FOLDERTAIL:stc.STC_MARK_LCORNERCURVE,
                     stc.STC_MARKNUM_FOLDEREND:stc.STC_MARK_CIRCLEPLUSCONNECTED,
                     stc.STC_MARKNUM_FOLDEROPENMID:stc.STC_MARK_CIRCLEMINUSCONNECTED,
                     stc.STC_MARKNUM_FOLDERMIDTAIL:stc.STC_MARK_TCORNERCURVE},
         'Square':{stc.STC_MARKNUM_FOLDEROPEN:stc.STC_MARK_BOXMINUS,
                   stc.STC_MARKNUM_FOLDER:stc.STC_MARK_BOXPLUS,
                   stc.STC_MARKNUM_FOLDERSUB:stc.STC_MARK_VLINE,
                   stc.STC_MARKNUM_FOLDERTAIL:stc.STC_MARK_LCORNER,
                   stc.STC_MARKNUM_FOLDEREND:stc.STC_MARK_BOXPLUSCONNECTED,
                   stc.STC_MARKNUM_FOLDEROPENMID:stc.STC_MARK_BOXMINUSCONNECTED,
                   stc.STC_MARKNUM_FOLDERMIDTAIL:stc.STC_MARK_TCORNER}}
